import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:freedom_flutter_mall/provider/theme_provider.dart';
import 'package:provider/provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'tabbar/main_tab_screens.dart';


class MainScreens extends StatefulWidget {
  const MainScreens({super.key});

  @override
  State<MainScreens> createState() => _MainScreensState();
}

final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

BuildContext? globalContext() => navigatorKey.currentState?.overlay?.context;

class _MainScreensState extends State<MainScreens> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MultiProvider(
        providers: [
          //主题色样式
          ChangeNotifierProvider(create: (_) => ThemeProvider()),
        ],
        child: Consumer<ThemeProvider> (
          builder: (context, themeProvider,child) =>  MaterialApp(
            title: "Freedom_flutter_mall",
            debugShowCheckedModeBanner: false,
            //样式
            theme: themeProvider.getTheme(),
            themeMode: themeProvider.getThemeMode(),
            navigatorKey: navigatorKey,
            scrollBehavior: MyCustomScrollBehavior().copyWith(
              scrollbars:false,
            ),
            home: AnnotatedRegion<SystemUiOverlayStyle>(
              value: SystemUiOverlayStyle.dark,
              child: ScreenUtilInit(
                designSize: const Size(375, 812),
                builder: (BuildContext context, Widget? child) {
                  return const MainTabScreens();
                },
              ),
            ),
          ),
        ),
    );
  }
}



class MyCustomScrollBehavior extends MaterialScrollBehavior {
  @override
  Set<PointerDeviceKind> get dragDevices => {
    PointerDeviceKind.touch,
    PointerDeviceKind.mouse,
    PointerDeviceKind.trackpad,
  };

  @override
  Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details,) {
    return StretchingOverscrollIndicator(
      axisDirection: details.direction,
      child: child,
    );
  }

  @override
  ScrollPhysics getScrollPhysics(BuildContext context) {
    return const ClampingScrollPhysics();
  }
}
